// 布局组件
const BasicLayout = () => import('@/layouts/BasicLayout.vue')

// 页面组件
const Home = () => import('@/views/home/index.vue')
const Books = () => import('@/views/books/index.vue')
const BookDetail = () => import('@/views/books/detail.vue')
const My = () => import('@/views/my/index.vue')
const Login = () => import('@/views/login/index.vue')
const NotFound = () => import('@/views/error/404.vue')

// 创建路由实例
const routes = [
  {
    path: '/',
    name: 'home',
    component: Home,
    meta: {
      title: '首页',
      keepAlive: true
    },
  },
  {
    path: '/',
    component: BasicLayout,
    redirect: '/',
    children: [
      {
        path: 'books',
        name: 'books',
        component: Books,
        meta: {
          title: '书库',
          keepAlive: true
        }
      },
      {
        path: 'books/:id',
        name: 'bookDetail',
        component: BookDetail,
        props: true,
        meta: {
          title: '书籍详情'
        }
      },
      {
        path: 'my',
        name: 'my',
        component: My,
        meta: {
          title: '个人中心',
          requiresAuth: true
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login,
    meta: {
      title: '登录'
    }
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'notFound',
    component: NotFound,
    meta: {
      title: '404'
    }
  }
]
export default routes